package com.client.ble.adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;

import com.base.adapter.BaseListAdapter;
import com.client.ble.R;

import java.util.List;

public class BleAdapter extends BaseListAdapter<BluetoothDevice, BleAdapter.ViewHolder> {

    public BleAdapter(Context context) {
        super(context);
    }

    public BleAdapter(Context context, List<BluetoothDevice> arrList) {
        super(context, arrList);
    }

    @Override
    public int adapterLayout() {
        return R.layout.adapter_ble;
    }

    @Override
    public ViewHolder createViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    public void onViewHolder(@NonNull ViewHolder holder, int position) {
        BluetoothDevice device = getItem(position);
        String mac = device.getAddress();
        String name = device.getName();
        holder.bleName.setText(String.format("%s\n%s", mac, name));
    }

    public static class ViewHolder extends BaseListAdapter.ViewHolder {
        private AppCompatTextView bleName;

        public ViewHolder(@NonNull View view) {
            super(view);
        }

        @Override
        public void bindViews(@NonNull View view) {
            bleName = view.findViewById(R.id.ble_name);
        }
    }
}
